var service_common = require("../../service/common.js");
var allUserList = [];
var searchUserList2 = [];
var page = 1;
Page({
  data: {
    searchUserList: {}
  },
  onLoad: function () {
    var that = this;
    page = 1;
    allUserList = [];
    searchUserList2 = [];
    service_common.fetchData(
      service_common.getUrl("user.getSeeCollectList"),
      {
        openid: getApp().globalData.userInfo.openid,
        page:page
      },
      function (res) {
        console.log(res.data.data)
        that.showData(res.data.data);
      },
      "GET"
    )
    wx.showLoading({
      title: '加载数据中',
      mask: true,
    })
  },
  onPullDownRefresh: function () {
    var that = this
    allUserList = [];
    searchUserList2 = [];
    page = 1;
    service_common.fetchData(
      service_common.getUrl("user.getSeeCollectList"),
      {
        openid: getApp().globalData.userInfo.openid,
        page:page
      },
      function (res) {
        console.log(res.data.data)
        that.showData(res.data.data);
      },
      "GET"
    )
  },

  //自定义显示
  showData: function (dataList) {
    console.log(dataList)
    for (var i = 0; i < dataList.data.length; i++) {
      allUserList.push(dataList.data[i]);
    }
    page++;
    //更新数据
    this.setData({
      searchUserList: allUserList
    })
    wx.hideLoading();
    wx.stopPullDownRefresh();
  },

  //点击查看名片
  viewCard: function (e) {
    add_form_id(e.detail.formId)
    console.log(1111)
    var openid = e.currentTarget.dataset.openid;
    wx.navigateTo({
      url: '/pages/other/other?openid=' + openid,
      success: function (res) {
        // success
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },

  //打电话
  callPhone: function (event) {
    var phone = event.target.dataset.phone;
    if (phone != "") {
      wx.makePhoneCall({
        phoneNumber: phone,
        success: function (res) {
          // success
        }
      })
    }
  },
  onReachBottom: function () {
    var that = this;
    wx.showLoading({
      title: '加载数据中',
      mask: true
    });
    console.log(page)
    service_common.fetchData(
      service_common.getUrl("user.getSeeCollectList"),
      {
        openid: getApp().globalData.userInfo.openid,
        page:page
      },
      function (res) {
        console.log(res.data.data)
        that.showData(res.data.data);
      },
      "GET"
    )
  }
})
//添加form_id
function add_form_id(form_id) {
  wx.request({
    url: getApp().globalData.API_Base_URL + '/formid/index/setFormId?openid=' + getApp().globalData.userInfo.openid + '&formid=' + form_id,
  })
}